#include <iostream>
#include <algorithm>

using namespace std;

const int T = 510;
int triangle[T][T];
int dp[T][T];
const int INF = 1e9;

int main()
{
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= i; j++)
            cin >> triangle[i][j];

    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= i + 1; j++)
            dp[i][j] = -INF;

    dp[1][1] = triangle[1][1];
    for (int i = 2; i <= N; i++)
        for (int j = 1; j <= i; j++)
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + triangle[i][j];

    int res = -INF;
    for (int i = 1; i <= N; i++)
        res = max(res, dp[N][i]);

    cout << res;

    return 0;
}
